package com.foreknow.util;

import com.foreknow.dao.impl.BusinessDaoImpl;
import com.foreknow.db.DBManager;
import com.foreknow.db.JdbcTemplate;
import com.foreknow.model.business;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ttc
 *��������dataֵ�ͱ�ͷcoulum�ƶ�̬��
 */
public class PropertyJtable {
	private static PropertyJtable jtable = null;
	private DefaultTableModel model = new DefaultTableModel();
	private Object [][]data=null;
	private String head[]=null;
	private PropertyJtable() {

	}

	public static PropertyJtable getJtable() {
		if (jtable == null) {
			jtable = new PropertyJtable();
		}
		return jtable;
	}

	/**
	 * ����data��coulum����һ���¶�̬��
	 * @Object data
	 * @String column
	 * @JTable
	 */
	public JTable newJtable(Object[][] data, String[] column) {
		model.setDataVector(data, column);
		JTable jtable = new JTable(model);
		return jtable;
	}

	/**
	 * ���¶�̬��
	 * @Object data
	 * @String column
	 */
	public void update(Object[][] data, String[] column) {
		model.setDataVector(data, column);
	}



	//生成表格数据
	/**
	 * @return
	 */
	public Object[][] queryData(List<Object> list){
		data=new Object[list.size()][head.length];
		for(int i=0;i<list.size();i++){         //遍历集合，将数据库中的数据放在二位数组中
			for(int j=0;j<head.length;j++){
				business o = (business) list.get(i);
				data[i][0]=o.getBusinessId();
				data[i][1]=o.getPassword();
				data[i][2]=o.getBusinessName();
				data[i][3]=o.getBusinessAddress();
				data[i][4]=o.getBusinessExplain();
				data[i][5]=o.getStarPrice();
				data[i][6]=o.getDeliveryPrice();
			}
		}
		return data;
	}

	//返回表头
	public String[] gethead(){
		head=new String[] {"businessId", "password", "businessName", "businessAddress", "businessExplain", "starPrice", "deliveryPrice"
		};
		return head;
	}
}
